package com.briup.pts.web.controller;

import com.briup.pts.entity.ManagerAnimal;
import com.briup.pts.entity.extend.ManagerAnimalExt;
import com.briup.pts.result.Result;
import com.briup.pts.service.ManagerAnimalService;
import com.github.pagehelper.PageInfo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Api(tags = "动物管理模块")
@RestController
@RequestMapping("/animal")
public class AnimalController {
    @Autowired
    ManagerAnimalService managerAnimalService;

    @ApiOperation("查询动物信息带分页带模糊")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "页数", value = "pageNum",required = true,paramType = "query"),
            @ApiImplicitParam(name = "单页条数", value = "pageSize",required = true,paramType = "query"),
            @ApiImplicitParam(name = "健康状况", value = "aHealthy"),
            @ApiImplicitParam(name = "动物性别", value = "aGender"),
    })
    @GetMapping
    public Result findByPage(@RequestParam Integer pageNum, @RequestParam int pageSize,
                             String aHealthy, String aGender) {
        PageInfo<ManagerAnimalExt> pageInfo = managerAnimalService.findByPage(pageNum, pageSize, aHealthy, aGender);
        return Result.success(pageInfo);
    }

    @PostMapping("/saveOrUpdate")
    public Result saveOrUpdate(@RequestBody ManagerAnimal animal){
        managerAnimalService.saveOrUpdate(animal);
//        managerAnimalService.addOrEditAnimal(animal);
        return Result.success();
    }

    @DeleteMapping("/deleteById/{id}")
    public Result removeById(@PathVariable String id){
        managerAnimalService.removeById(id);
        return Result.success();
    }

    @DeleteMapping("/deleteByIdAll")
    public Result removeBatch(@RequestBody List<String> ids){
        managerAnimalService.removeBatch(ids);
        return Result.success();
    }

    @GetMapping("/QRcode")
    public Result QRcode(String animalId){
        managerAnimalService.creatQRcode();
        return Result.success();
    }

}
